<template>
    
    <!-- 组件的模板 -->
    <div class="page user-select multi-select">
        <ul class="list com-border-top com-border-bottom" v-show="searchInput.length">
            <li class="weui-cells_checkbox has-hierarchy"  v-for="group in searchResultList">
                <label class="touch" for="{{group.id}}">
                    <input class="weui-check" type="checkbox" value="{{group.id}}"  id="{{group.id}}" v-model="selectGroupList">
                    <i class="weui-icon-checked"></i>
                    <div class="info com-border-bottom">
                        <p class="title">{{group.name}}</p>
                         <!-- <div class="hierarchy" v-show="group.children.length" @click="stepNext(group.id)">下级</div> -->
                    </div>
                </label>
            </li>
        </ul>
        <div class="count bg-color com-border-top">
            <span class="num">已选择：<em>{{selectGroupList.length}}个部门</em></span>
            <a class="mod-btn-s-1" @click="submitResult">确定</a>
        </div>
    </div>
</div>

</template>

<script>
    /**
     *  引入工具类库 或 Native API
     *  example : import widget from 'gapi/widget'
     */
    
    /**
     *  引入组件 以及 组件接口(Action)
     *  example : import Somecomponents from 'components/Somecomponents/Somecomponents'
     */
    import cache from 'gapi/cache.js'
    import commonPage from 'clientApi/commonPage.js'
    import searchPage from 'clientApi/searchPage.js'
    
    /**
     *  组件实例对象
     */
    export default {
        components: {
            
        },
        data: function(){
            return{ 
               searchInput:'',
               selectGroupList:[],
               allGroupList:[]
            }
        },
        computed:{
            searchResultList(){
                var searchResultList = []
                this.allGroupList.forEach((item)=>{
                    if(item.name.indexOf(this.searchInput)>-1){
                        searchResultList.push(item)
                    }
                })
                return searchResultList
            }
        },
        vuex: {
            getters: {

            },
            actions: {

            }
        },
        methods: {
            /**
             * 初始化
             * @method init
             * @public
             * @return {Null} void
             */
            init (){    
                cache.getMemoryCache('participantGroup', (data) => {
                    if(data){
                        this.selectGroupList = data
                    }
                })
                cache.getMemoryCache('allGroupList', (data) => {
                    if(data){
                        this.allGroupList = data
                        console.log(this.allGroupList)
                    }
                })
                window.getSearchResult=(data)=>{
                    this.searchInput = data
                }
            },
            //提交
            submitResult() {
                var participantGroup = this.selectGroupList
                let GroupNameList = []
                this.searchResultList.forEach((i) => {
                    participantGroup.forEach((k) =>{
                        if(i.id == k){
                            GroupNameList.push(i.name)
                        }
                    })                    
                    
                })
                cache.getMemoryCache('webViewID',(data)=>{
                    if(data){
                      commonPage.goBack(1,{'goBackKey':'submit','key':'participantGroup','value':participantGroup,name: GroupNameList},data.webViewID)
                    }
                })
                
            }
        },
        created(){
            this.init();
            
        }
        
    }

    
</script>

<!-- CSS 样式 -->
<style src="../../node_modules/weui/dist/style/weui.css"></style>
<style src="../../static/css/common.css"></style>
<style src="../../static/css/user-list.css"></style>
